#include "rwmake.ch"
#include "topconn.ch"

/**********
*
*   DVGERAL() - Retorna o Banco de Pagamento do Boleto
*   -------
*/
USER FUNCTION DIGITO()
LOCAL cReturn := SPACE(01)

IF !EMPTY(SE2->E2_CODBAR)
   cReturn := SUBSTR(SE2->E2_CODBAR,5,1)
ELSE
   cReturn := SUBSTR(SE2->E2_LINHAD,33,1)
ENDIF
RETURN(cReturn)


/**********
*
*   VLRBOLETO() - Retorna o Valor Boleto
*   -----------
*/
USER FUNCTION VLRBOLETO()
LOCAL cReturn := SPACE(14)

IF !EMPTY(SE2->E2_CODBAR)
   cReturn := STRZERO(VAL(SUBSTR(SE2->E2_CODBAR,06,14)),14,0)
ELSE
   cReturn := STRZERO(VAL(SUBSTR(SE2->E2_LINHAD,34,14)),14,0)
ENDIF
RETURN(cReturn)


/**********
*
*   CAMPOLIVRE() - Retorna o Campo Livre
*   -----------
*/
USER FUNCTION CAMPOLIVRE()
LOCAL cReturn := SPACE(25)

IF !EMPTY(SE2->E2_CODBAR)
   cReturn := SUBSTR(SE2->E2_CODBAR,20,25)
ELSE
   cReturn := SUBSTR(SE2->E2_LINHAD,05,05)+SUBSTR(SE2->E2_LINHAD,11,10)+SUBSTR(SE2->E2_LINHAD,22,10)
ENDIF
RETURN(cReturn)